<template>
	<view class="webSocket">
		
	</view>
</template>

<script>
	export default{
		data(){
			return{
				list: [],
			}
		},
		onLoad() {
			this.toWebSocket()
		},
		methods:{
			toWebSocket(){
				var that = this;
				uni.connectSocket({
					url: 'ws://192.168.31.118:8080/webSocket', //请输入链接websocke.io地址
					success() {
						uni.onSocketOpen(function(res) {
							console.log(res)
							uni.showToast({
								icon: 'none',
								position: 'bottom',
								title: 'Socket连接已打开！'
							});
							uni.sendSocketMessage({
								data: message, //自身定义一个发送消息对象
								success: function() {
									uni.onSocketMessage(function(res) {
										var s = JSON.parse(res.data);
										that.list.push({
											con: s.msg,
											ss: s.name
										});
									});
								},
								fail: function() {
									uni.showToast({
										icon: 'none',
										position: 'bottom',
										title: '数据发送失败'
									});
								}
							});
						});
					}
				});
			}
			
		}
	}
</script>

<style>
</style>
